package com.xqzgj.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xqzgj.common.annotation.Log;
import com.xqzgj.common.core.controller.BaseController;
import com.xqzgj.common.core.domain.AjaxResult;
import com.xqzgj.common.enums.BusinessType;
import com.xqzgj.system.domain.StockStatistics;
import com.xqzgj.system.service.IStockStatisticsService;
import com.xqzgj.common.utils.poi.ExcelUtil;
import com.xqzgj.common.core.page.TableDataInfo;

/**
 * 库存统计Controller
 */
@RestController
@RequestMapping("/system/statistics")
public class StockStatisticsController extends BaseController {
    @Autowired
    private IStockStatisticsService stockStatisticsService;

    /**
     * 查询库存统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockStatistics stockStatistics) {
        startPage();
        List<StockStatistics> list = stockStatisticsService.selectStockStatisticsList(stockStatistics);
        return getDataTable(list);
    }

    /**
     * 导出库存统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:export')")
    @Log(title = "库存统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StockStatistics stockStatistics) {
        List<StockStatistics> list = stockStatisticsService.selectStockStatisticsList(stockStatistics);
        ExcelUtil<StockStatistics> util = new ExcelUtil<StockStatistics>(StockStatistics.class);
        return util.exportExcel(list, "库存统计数据");
    }

    /**
     * 获取库存统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockStatisticsService.selectStockStatisticsById(id));
    }

    /**
     * 新增库存统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:add')")
    @Log(title = "库存统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockStatistics stockStatistics) {
        return toAjax(stockStatisticsService.insertStockStatistics(stockStatistics));
    }

    /**
     * 修改库存统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:edit')")
    @Log(title = "库存统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockStatistics stockStatistics) {
        return toAjax(stockStatisticsService.updateStockStatistics(stockStatistics));
    }

    /**
     * 删除库存统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:remove')")
    @Log(title = "库存统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockStatisticsService.deleteStockStatisticsByIds(ids));
    }

    /**
     * 获取库存统计图表数据
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:chart')")
    @GetMapping("/chart")
    public AjaxResult getChartData(StockStatistics stockStatistics) {
        return success(stockStatisticsService.getStockStatisticsChartData(stockStatistics));
    }

    /**
     * 获取库存统计报表数据
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:report')")
    @GetMapping("/report")
    public AjaxResult getReportData(StockStatistics stockStatistics) {
        return success(stockStatisticsService.getStockStatisticsReportData(stockStatistics));
    }
}